package com.nearby.demand.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.nearby.demand.R;
import com.nearby.demand.fragment.PageFragment;

import java.util.List;

/**
 * Created by Administrator on 2015/11/18.
 */
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
    final int PAGE_COUNT = 3;
    private String tabTitles[];
    private int[] imageResId;
    private Context context;

    private List<PageFragment> fragments;

    /**
     * @param fm
     * @param context
     * @param fragments
     */
    public SimpleFragmentPagerAdapter(FragmentManager fm, Context context, List<PageFragment> fragments) {
        super(fm);
        this.context = context;
        this.fragments = fragments;
        tabTitles = new String[]{"New Tu", "Attention", "Nearby"};
        imageResId = new int[]{
                R.drawable.aii,
                R.drawable.aii,
                R.drawable.aii
        };

    }

    @Override
    public Fragment getItem(int position) {
//        Log.i("ggggg", "getItem="+position);
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return tabTitles.length;
    }

    @Override
    public int getItemPosition(Object object) {
        //加此方法可以使viewpager可以进行刷新
        return PagerAdapter.POSITION_NONE;
    }

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.page_fragment_title, null);
        TextView tv = (TextView) view.findViewById(R.id.textView);
        tv.setText(tabTitles[position]);
//        ImageView img = (ImageView) view.findViewById(R.id.imageView);
//        img.setImageResource(imageResId[position]);
        return view;
    }

//    @Override
//    public float getPageWidth(int position) {
//        return 0.93f; //权重比例
//    }

    @Override
    public CharSequence getPageTitle(int position) {
        // Generate title based on item position
        // return tabTitles[position];

        return null;
    }
}
